home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / parallax / more_exa.tar / more / Vision / mk3d.c < prev    next >
C/C++ Source or Header  |  1991-11-18  |  3KB  |  112 lines

  1. /*******************************************************************************/
  2. /*   File     : mk3d.c                                                         */
  3. /*                                                                             */
  4. /*   Function : to take the left and right image of a picture and overlays them*/ 
  5. /*              to one image :                                                 */
  6. /*              The original black&white pixel of the left image turns to red. */ 
  7. /*              The original b&w pixel of the right image turns to green.      */ 
  8. /*              With red-green glasses now you can watch the picture           */ 
  9. /*              in 3-D.                                                        */  
  10. /*                                                                             */
  11. /*   Author   : Michael C. Ancutici                                            */
  12. /*                                                                             */
  13. /*   Date     : 12.09.91                                                       */ 
  14. /*******************************************************************************/  
  15.  
  16. #include <stdio.h>
  17.  
  18. FILE *inl, *inr , *out ;
  19.  
  20. int heigth, width, i, j , white;
  21.  
  22. char hl, hr, h1, h2 ; 
  23. char black =  (char)( 0 );
  24. int backgr;
  25. int BLACK = 0;
  26. int WHITE = 1;
  27. char input_name_l[100] , input_name_r[100] , output_name[100] , help[100]; 
  28.  
  29. main( argc , argv )
  30.   int   argc ;
  31.   char *argv[] ;
  32. {
  33.   if( argc == 1 || argc > 3)
  34.    {
  35.     printf("\n Usage: mk3d [b] <filename>\n" ) ;
  36.     printf(  "        - filename without extension .l.ppm or .r.ppm\n" ) ;
  37.     printf(  "        - b for black background (additiv)\n");
  38.     printf(  "        - default background is white (subtractive)\n");
  39.     exit(20) ;
  40.    }
  41.  
  42.  
  43.   strcpy( help , argv[1]) ;
  44.   if (argc == 3 && help[0] == 'b' && help[1] == (char)( 0 ) )
  45.     backgr = BLACK;
  46.   else 
  47.     backgr = WHITE;
  48.  
  49.   if (argc == 3) 
  50.     strcpy( input_name_l , argv[2] ) ;
  51.   else
  52.     strcpy( input_name_l , argv[1] ) ;
  53.   strcpy( output_name  , input_name_l ) ;
  54.   strcpy( input_name_r , input_name_l ) ;
  55.  
  56.   strcat( output_name  , ".3d.ppm" ) ;
  57.   strcat( input_name_l , ".l.ppm" ) ;
  58.   strcat( input_name_r , ".r.ppm" ) ;
  59.   
  60.  if( !(inl = fopen( input_name_l , "r" )))
  61.    { printf("\n ERROR: Cound not open input file %s !\n",input_name_l ) ; exit(20) ; }
  62.  
  63.  if( !(inr = fopen( input_name_r , "r" )))
  64.    { printf("\n ERROR: Cound not open input file %s !\n",input_name_r ) ; exit(20) ; }
  65.  
  66.  if( !(out = fopen( output_name , "w" )))
  67.    { printf("\n ERROR: Cound not open output file %s !\n",output_name ) ; exit(20) ; }
  68.   
  69.  
  70.  fgets(help , 100 , inr); 
  71.  fprintf( out , help ) ;
  72.  
  73.  fscanf(  inr , "%d\n%d\n%d\n" , &width , &heigth , &white ) ;
  74.  fprintf( out , "%1d\n%1d\n%1d\n" ,width+1, heigth+1, white ) ;
  75.  
  76.  
  77.  for( i=1 ; i<5 ; ++i)
  78.    fgets(help , 100 , inl);
  79.    
  80.  for( i=0 ; i<heigth+1 ; ++i )
  81.   {
  82.   for( j=0 ; j<width+1 ; ++j )
  83.    {
  84.    if (j == width | i == heigth)
  85.      hl = black;
  86.    else
  87.      fscanf(inl, "%c%c%c" , &hl, &h1, &h2 );
  88.  
  89.    if (j == 0 | i == 0 )
  90.      hr = black;
  91.    else
  92.      fscanf(inr, "%c%c%c" , &hr, &h1, &h2 );
  93.  
  94.    if (backgr == WHITE) {
  95.      if (hl == black && hr == black) 
  96.        fprintf(out, "%c%c%c", white, white, white);
  97.      else
  98.        fprintf(out, "%c%c%c", white-hl, white-hr, black);
  99.      }
  100.    else
  101.      fprintf(out, "%c%c%c",hl, hr, black);
  102.  
  103.    }
  104.   }
  105.  
  106.  fclose( inl ) ;
  107.  fclose( inr ) ;
  108.  fclose( out ) ;
  109.  
  110. }
  111.  
  112.